from abc import ABCMeta,abstractmethod
from pandas import DataFrame

class Notice:  # 抽象发布者
    def __init__(self):
        self.observers = []  # 用于存储订阅者信息
    def attach(self,obs):
        self.observers.append(obs)
    def detach(self,obs):
        self.observers.remove(obs)
    def notify(self):
        for obs in self.Observers:
            obs.update(self)


class Observer(ABCMeta): # 抽象的观察者
    @abstractmethod
    def update(self,notice:Notice):
        pass



class StaffNotice(Notice): # 具体的发布者
    def __init__(self,df_data:DataFrame=DataFrame()):
        super().__init__()
        self.__df_data = df_data
        
    @property
    def df_data(self):
        return self.__df_data
    @df_data.setattr
    def df_data(self,df_data):
        self.__df_data = df_data
        self.notify()
class Data_Save(Observer): # 保存数据
    def __init__(self):
        super().__init__()
        self.df_data = DataFrame()
    def update(self, notice):
        self.df_data = notice.df_data
        

class Data_Show(Observer): # 保存数据
    def __init__(self):
        super().__init__()
        self.df_data = DataFrame()
    def update(self, notice):
        self.df_data = notice.df_data